home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 June / MacFormat 25.iso / Shareware City / Developers / macgzip_03b2-src / macos / think / PopUp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-09  |  1.9 KB  |  94 lines  |  [TEXT/KAHL]

  1. /*
  2.  * SPDsoft 1994 for MacGzip 0.2.2
  3.  *
  4.  * From: Pop-up Menu Example
  5.  * Bryan Stearns 05May87 
  6.  */
  7.  
  8. #include "PopUp.h"
  9.  
  10.  
  11. PopUpType    PopUp[NumOfPopUps];
  12.  
  13. #define PUP        PopUp[theItem-PopUpBaseItem]
  14.  
  15. pascal void DrawPopUp(DialogPtr theDialog, int theItem)
  16. {
  17.     Str255    curStr;
  18.     int        newWid, newLen, wid;
  19.     Rect    r;
  20.     
  21.     r = PopUp[theItem-PopUpBaseItem].MenuRect;
  22.     
  23.     GetItem(PUP.Menu,PUP.Selection,curStr);
  24.     InsetRect(&r,-1,-1);
  25.     
  26.     wid = (r.right - r.left) - (LeftSlop + RightSlop);
  27.     newWid = StringWidth(curStr);
  28.     
  29.     if (newWid > wid )
  30.     {
  31.         newLen = (int) curStr[0];
  32.         wid = wid - CharWidth('…');
  33.         do
  34.         {
  35.             newWid = newWid - CharWidth(curStr[newLen]);
  36.             newLen--;
  37.         }while((newWid > wid) && (curStr[0] != 0x00));
  38.  
  39.         newLen ++;
  40.         curStr[newLen] = '…';
  41.         curStr[0] = (char)newLen;
  42.  
  43.     }
  44.     FrameRect(&r);
  45.     MoveTo(r.right,r.top+2); LineTo(r.right,r.bottom);
  46.     LineTo(r.left+2,r.bottom);
  47.     
  48.     MoveTo(r.left+LeftSlop,r.bottom-BotSlop);
  49.     DrawString(curStr);
  50. }
  51.  
  52. int DoPopUp(DialogPtr theDialog, int theItem)
  53. {
  54.     Rect    r;
  55.     Point    popLoc;
  56.     long    chosen;
  57.     int        choice;
  58.     
  59.     r = PopUp[theItem-PopUpBaseItem].MenuRect;
  60.  
  61. /*    We're going to pop up our menu. Insert our menu into the menu list,
  62.  *    then call CalcMenuSize (to work around a bug in the Menu Manager),
  63.  *    then call PopUpMenuSelect and let the user drag around. Note that the
  64.  *    (top,left) parameters to PopUpMenuSelect are our item’s, converted to
  65.  *    global coordinates.
  66.  */
  67.  
  68.     InvertRect(&r);
  69.     InsertMenu(PUP.Menu,-1);
  70.     
  71.     popLoc = topLeft(r);
  72.     LocalToGlobal(&popLoc);
  73.     CalcMenuSize(PUP.Menu);
  74.     chosen = PopUpMenuSelect(PUP.Menu, popLoc.v, popLoc.h, PUP.Selection);
  75.  
  76.     InvertRect(&r);
  77.     DeleteMenu(PUP.MenuID);
  78.  
  79.     if (chosen != 0)
  80.     {
  81.         choice = LoWord(chosen);
  82.         if ( choice != PUP.Selection)
  83.         {
  84.             SetItemMark(PUP.Menu,PUP.Selection,noMark);
  85.             SetItemMark(PUP.Menu,choice,checkMark);
  86.             PUP.Selection = choice;
  87.                         
  88.             EraseRect(&r);
  89.             DrawPopUp(theDialog, theItem);
  90.         }
  91.     }
  92.     
  93.     return( choice ); 
  94. }